package com.xiaotu.es.service.impl;

import com.xiaotu.es.mapper.EsUserMapper;
import com.xiaotu.es.model.User;
import com.xiaotu.es.service.EsUserService;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhangxiao
 * @create 2022-04-11 15:48
 */
@Service
public class EsUserServiceImpl implements EsUserService {

    @Autowired
    private EsUserMapper esUserMapper;

    @Autowired
    private ElasticsearchRestTemplate template;

    @Override
    public List<User> searchUser(Integer pageNum, Integer pageSize, String school) {
        TermQueryBuilder termQuery = QueryBuilders.termQuery("school", school);
        Page<User> search = (Page<User>) esUserMapper.search(termQuery);
        return search.getContent();
    }

}
